"""
增删改查
"""
from pymysql import Connection

conn = None
try:
    # 1. 创建SQL连接对象
    conn = Connection(
        host='localhost',
        port=3306,
        user='root',
        password='root',
        charset='utf8',
        database='db2',
        autocommit=True # 自动提交
    )
    # 2. 获取游标对象
    cursor = conn.cursor()
    # 3. 定义SQL
    sql = """
        insert into t_user values(null,'崔龙腾','男',18,'吉林省长春市')
    """
    # 4. 执行SQL
    cursor.execute(sql)
    # 5. 出了查询，增，删，改必须手动提交
    # conn.commit()
    print('添加成功')
    print(f'自增的id是:{conn.insert_id()}')
except Exception as e:
    print(e)
finally:
    if conn:
        conn.close()